package com.bcxk.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bcxk.constants.Constants;
import com.bcxk.entity.dto.*;
import com.bcxk.entity.po.MinSuPo;
import com.bcxk.entity.po.RoomPo;
import com.bcxk.entity.vo.MinSuVo;
import com.bcxk.mapper.HomeStayMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HomeStayService extends ServiceImpl<HomeStayMapper, Homestay> {
    @Resource
    HomeStayMapper homeStayMapper;
    @Resource
    RoomService roomService;
    @Resource
    MinSuImgService minSuImgService;
    @Resource
    CommentService commentService;

    @Transactional(readOnly = true)
    public IPage<MinSuVo> getMinSuListByName(String destName, int pageNum) {
        Page<MinSuVo> page = new Page<>(pageNum, Constants.MINSU_LEN);
        return homeStayMapper.getMinSuListByName(page,destName);
    }

    @Transactional(readOnly = true)
    public MinSuPo getMinSuByMinSuId(Long minsuId) {
        MinSuPo minSuPo = homeStayMapper.getMinSuByMinSuId(minsuId);
        List<MinsuImg> minsuImgs = minSuImgService.getMinSuImgsByMinSuId(minsuId);
        minSuPo.setImgs(minsuImgs);
        List<Comment> comments = commentService.getCommentsByMinSuId(minsuId);
        minSuPo.setComments(comments);
        List<RoomPo> rooms = roomService.getRoomsByMinSuId(minsuId);
        minSuPo.setRoomPos(rooms);
        return minSuPo;
    }
}
